#!/bin/bash

# 诊断Go版本问题的脚本

echo "🔍 Go环境诊断"
echo "================================"

echo "1. Go版本信息:"
go version

echo -e "\n2. Go环境变量:"
go env | grep -E "(GOVERSION|GOROOT|GOPATH|GOOS|GOARCH)"

echo -e "\n3. 检查Go安装路径:"
which go
ls -la $(which go)

echo -e "\n4. 检查是否有多个Go版本:"
find /usr -name "go" -type f 2>/dev/null | head -10
find /usr/local -name "go" -type f 2>/dev/null | head -10

echo -e "\n5. 检查当前目录Go模块信息:"
if [ -f "go.mod" ]; then
    echo "go.mod内容:"
    cat go.mod
else
    echo "❌ 未找到go.mod文件"
fi

echo -e "\n6. 尝试简单的go命令:"
echo "go env GOVERSION:"
go env GOVERSION

echo -e "\n🔧 建议的解决方案:"
echo "1. 更新Go到稳定版本 (1.19-1.22)"
echo "2. 清理go模块缓存: go clean -modcache"  
echo "3. 重新初始化go模块: go mod tidy"
echo "4. 使用go build代替go run"
